Compound triggers were introduced to ease the implementation of multiple triggers which need to work in cooperation.
Typically, a FOR EACH ROW
trigger accumulates facts, and an AFTER STATEMENT
trigger performs the actual changes.
The compound trigger can hold a state common to all the triggers it defines, thereby removing the need to use package variables. This approach is
sometimes the only possible one, as when avoiding a mutating table ORA-04091
error, or it can be used to get better performance.
However, there is no point in defining a compound trigger which contains only a single trigger, since there is no state to be shared. In such
cases, a simple trigger should be used instead.
Noncompliant code example
CREATE OR REPLACE TRIGGER my_trigger -- Noncompliant; defines a single trigger
FOR INSERT ON my_table
COMPOUND TRIGGER
AFTER EACH ROW IS
BEGIN
DBMS_OUTPUT.PUT_LINE('New row inserted!');
END AFTER EACH ROW;
END;
/
Compliant solution
CREATE OR REPLACE TRIGGER my_trigger
AFTER INSERT
ON my_table
FOR EACH ROW
BEGIN
DBMS_OUTPUT.PUT_LINE('New row inserted!');
END;
/